USE [Biblioteca]
GO
/****** Object:  User [biblioteca]    Script Date: 11/29/2009 23:49:35 ******/
CREATE USER [biblioteca] FOR LOGIN [biblioteca] WITH DEFAULT_SCHEMA=[dbo]
GO
/****** Object:  Table [dbo].[tb_categoria]    Script Date: 11/29/2009 23:49:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_categoria](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[ds_categoria] [varchar](50) NOT NULL,
 CONSTRAINT [PK_tb_categoria] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_cliente]    Script Date: 11/29/2009 23:49:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_cliente](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[nm_cliente] [varchar](100) NOT NULL,
	[nr_cpf] [char](11) NOT NULL,
	[tp_sexo] [int] NOT NULL,
 CONSTRAINT [PK_tb_cliente] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_livro]    Script Date: 11/29/2009 23:49:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_livro](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[nm_livro] [varchar](100) NOT NULL,
	[nm_autor] [varchar](100) NOT NULL,
	[ds_livro] [varchar](50) NOT NULL,
	[id_categoria] [int] NOT NULL,
	[tp_status] [int] NOT NULL,
	[valor] [float] NOT NULL,
 CONSTRAINT [PK_tb_aluno] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_emprestimo]    Script Date: 11/29/2009 23:49:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tb_emprestimo](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[id_livro] [int] NOT NULL,
	[id_cliente] [int] NOT NULL,
	[dt_emprestimo] [datetime] NOT NULL,
	[dt_devolucao] [datetime] NOT NULL,
 CONSTRAINT [PK_tb_emprestimo] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Check [CK_tb_cliente_tp_sexo]    Script Date: 11/29/2009 23:49:35 ******/
ALTER TABLE [dbo].[tb_cliente]  WITH CHECK ADD  CONSTRAINT [CK_tb_cliente_tp_sexo] CHECK  (([tp_sexo]=(1) OR [tp_sexo]=(2) OR [tp_sexo]=(3)))
GO
ALTER TABLE [dbo].[tb_cliente] CHECK CONSTRAINT [CK_tb_cliente_tp_sexo]
GO
/****** Object:  ForeignKey [FK_tb_emprestimo_tb_cliente]    Script Date: 11/29/2009 23:49:35 ******/
ALTER TABLE [dbo].[tb_emprestimo]  WITH CHECK ADD  CONSTRAINT [FK_tb_emprestimo_tb_cliente] FOREIGN KEY([id_cliente])
REFERENCES [dbo].[tb_cliente] ([id])
GO
ALTER TABLE [dbo].[tb_emprestimo] CHECK CONSTRAINT [FK_tb_emprestimo_tb_cliente]
GO
/****** Object:  ForeignKey [FK_tb_emprestimo_tb_livro]    Script Date: 11/29/2009 23:49:35 ******/
ALTER TABLE [dbo].[tb_emprestimo]  WITH CHECK ADD  CONSTRAINT [FK_tb_emprestimo_tb_livro] FOREIGN KEY([id_livro])
REFERENCES [dbo].[tb_livro] ([id])
GO
ALTER TABLE [dbo].[tb_emprestimo] CHECK CONSTRAINT [FK_tb_emprestimo_tb_livro]
GO
/****** Object:  ForeignKey [FK_tb_livro_tb_categoria]    Script Date: 11/29/2009 23:49:35 ******/
ALTER TABLE [dbo].[tb_livro]  WITH CHECK ADD  CONSTRAINT [FK_tb_livro_tb_categoria] FOREIGN KEY([id_categoria])
REFERENCES [dbo].[tb_categoria] ([id])
GO
ALTER TABLE [dbo].[tb_livro] CHECK CONSTRAINT [FK_tb_livro_tb_categoria]
GO
